package com.qzsf.backend.mapper;


import com.qzsf.backend.entity.Notification;
import com.qzsf.backend.vo.NotificationVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/*
 * @Author: Dennis Chen
 * @CreateTime: 2024/11/22 16:27 周五
 * @Email 1429278462@qq.com
 * @Remark 通知数据访问层
 * @Version 1.0
 */
@Mapper
@Repository
public interface NotificationMapper {
    @Insert("insert into notification (auth_id, title, message, is_read) VALUES (#{authId},#{title},#{message},#{isRead})")
    int createNotification(Notification notification);

    @Select("select b.name,a.title,a.message,a.created_at from notification a left join user_profile b on a.auth_id = b.id")
    List<NotificationVO> getNotification();

    @Select("select count(*) from notification where auth_id = #{id} and is_read = 0")
    int getUnreadMessageCount(int id);

    @Select("select * from notification where auth_id = #{id}")
    List<Notification> getUserNotification(int id);

    @Update("update notification set is_read = 1 where auth_id = #{id}")
    int readUserMessage(int id);
}
